import {Component, Input, OnInit} from '@angular/core';

@Component({
  selector: 'app-show-result',
  templateUrl: './show-result.component.html',
  styleUrls: ['./show-result.component.scss']
})
export class ShowResultComponent implements OnInit {
  option: any;
  chartSize = {height: '300px', width: '400px'};
  personAndCore = {
    1: '完美型',
    2: '助人型',
    3: '成就型',
    4: '自我型',
    5: '思考型',
    6: '疑惑型',
    7: '活跃型',
    8: '领袖型',
    9: '和平型',
  };
  @Input() data;
  constructor() {
    this.option = {
      tooltip: {
        trigger: 'item'
      },
      legend: {
        orient: 'vertical',
        left: 'left',
      },
      series: [
        {
          name: '人格分析',
          type: 'pie',
          radius: '50%',
          data: [
            // {value: 1048, name: '搜索引擎'},
            // {value: 735, name: '直接访问'},
            // {value: 580, name: '邮件营销'},
            // {value: 484, name: '联盟广告'},
            // {value: 300, name: '视频广告'}
          ],
          emphasis: {
            itemStyle: {
              shadowBlur: 10,
              shadowOffsetX: 0,
              shadowColor: 'rgba(0, 0, 0, 0.5)'
            }
          }
        }
      ]
    };
  }

  ngOnInit() {
    const dataObj = JSON.parse(this.data);
    // tslint:disable-next-line:forin
    for (const key in dataObj) {
      this.option.series[0].data.push({value: dataObj[key], name: this.personAndCore[key]});
    }
    console.log(this.option.series[0].data);
  }

}
